<template>
	<view>
		<view class="nav flex-aro">
			<view @tap="changeStatus" :class="'item ' + (status == 0 ? 'active' : '')" data-status="0">消费通知</view>
			<view @tap="changeStatus" :class="'item ' + (status == 1 ? 'active' : '')" data-status="1">系统消息</view>
		</view>
		<view style="width: 100%;height: 72rpx;"></view>
		<navigator :url="'/pages2/shop/message-detail/message-detail?id='+item.id" class="flex list" v-for="(item,index) in list" :key='index'>
			<image src="/static/images/lingdang.png" class="icon flex-grow-0"></image>
			<view class="flex-grow-1">
				<view class="flex-bet">
					<view class="name" v-if="item.type==1">系统消息</view>
					<view class="name" v-if="item.type==2">消费通知</view>
					<view class="name" v-if="item.type==3">消费通知</view>
					<view class="time">{{item.createtime}}</view>
				</view>
				<view class="text">{{item.title}}</view>
			</view>
		</navigator>
		<view v-if="!has_more" style="color: #666;text-align: center;margin: 15rpx;">没有了~</view>
	</view>
</template>

<script>
	import {Message} from '../../../apirequest/message-model.js';
	var m = new Message();
	export default {
		data() {
			return {
				status: 0,
				list: [],
				page:1,
				has_more:true
			}
		},
		onShow() {
			this._getList();
		},
		onReachBottom() {
			this._getList();
		},
		methods: {
			_getList(){
				var that = this;
				if(!this.has_more){
					return;
				}
				m.get_msg_list({page:this.page,type:this.status},(res) => {
					if(res.code == 1){
						that.list = that.list.concat(res.data.data)
						that.page = that.page+1
						that.has_more = res.data.has_more
					}
				})
			},
			changeStatus(e) {
				this.status = e.currentTarget.dataset.status
				this.page = 1
				this.has_more = true
				this.list = []
				this._getList()
			},
		}
	}
</script>

<style lang="scss">
	page {
		font-size: 0.85rem;
	}

	.nav {
		background: #fff;
		position: fixed;
		top: 0;
		left: 0;
		width: 100%;

		.item {
			padding: 15rpx 0;
		}

		.active {
			border-bottom: 5rpx solid #FF4544;
			color: #FF4544;
		}
	}

	.list {
		padding: 20rpx 25rpx;
		border-bottom: 1px solid #efeff4;
		background: #fff;

		.icon {
			width: 45rpx;
			height: 45rpx;
			margin-right: 20rpx;
		}

		.name {
			font-size: 0.85rem;
			font-weight: 700;
		}

		.text {
			color: #999;
			margin-top: 15rpx;
			white-space: nowrap;
			text-overflow: ellipsis;
			overflow: hidden;
			font-size: 0.75rem;
		}

		.time {
			color: #999;
			font-size: 0.75rem;
		}
	}
</style>
